Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms


Public Class EnrollDlg

    Dim _appSpecificParticipantId As String

    Public Property AppSpecificParticpantId() As String
        Get
            Return _appSpecificParticipantId
        End Get
        Set(ByVal value As String)
            _appSpecificParticipantId = value
        End Set
    End Property

    Private Sub Form_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        'Create a random value for appliction specific participant id
        'The user can further edit it anyway
        Me.txtAppSpecificParticipantId.Text = System.Guid.NewGuid().ToString()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub

    Private Sub btnOK_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnOK.Click
        Dim applicationSpecificParticipantId As String = txtAppSpecificParticipantId.Text.Trim()
        Dim participantName As String = txtParticipantName.Text.Trim()
        Dim securityQuestion As String = txtSecurityQuestion.Text.Trim()
        Dim securityAnswer As String = txtSecurityAnswer.Text.Trim()

        If String.IsNullOrEmpty(applicationSpecificParticipantId) OrElse _
            String.IsNullOrEmpty(participantName) OrElse _
            String.IsNullOrEmpty(securityQuestion) OrElse _
            String.IsNullOrEmpty(securityAnswer) Then
            MessageBox.Show("Please enter values for all fields")
            Exit Sub
        End If
        Try
            'Call HealthVault and obtain a particpantCode for this participant
            Dim participantCode As String = DCHelper.Functions.CreateParticipantIdentityCode(participantName, _
                    securityQuestion, securityAnswer, applicationSpecificParticipantId)

            'Update the local data storage with this new participant
            XmlStore.AddParticipantToLocalStore(applicationSpecificParticipantId, _
                    participantName, _
                    DateTime.Now, _
                    participantCode, _
                    securityQuestion, _
                    securityAnswer)

            Me.DialogResult = System.Windows.Forms.DialogResult.OK
            Me.Close()

            'Set the application specific id of the participant just created
            'to this dialog's member variable so that the calling form can use it
            AppSpecificParticpantId = applicationSpecificParticipantId
        Catch ex As Exception
            MessageBox.Show("Exception:" + ex.Message)
        End Try

    End Sub
End Class